<template>
  <el-form ref="searchForm" :model="searchForm" label-width="120px">
    <el-row v-if="conditionCount > 0">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="手机号" prop="userPhone" label-for="userPhone">
          <el-input
            v-model="searchForm.userPhone"
            element-id="userPhone"
            placeholder="请输入手机号"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="昵称" prop="userNickname" label-for="userNickname">
          <el-input
            v-model="searchForm.userNickname"
            element-id="userNickname"
            placeholder="请输入昵称"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="店铺标题" prop="shopTitle" label-for="shopTitle">
          <el-input
            v-model="searchForm.shopTitle"
            element-id="shopTitle"
            placeholder="请输入店铺标题"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-button
          type="primary"
          style="margin-left: 10px;"
          :loading="loading.search"
          @click="handleSubmit"
        >搜索</el-button>
        <el-button @click="handleReset">重置</el-button>
        <a v-if="conditionCount > 3" style="margin-left: 10px;" @click="collapse = !collapse">
          <el-button type="text" v-if="!collapse">
            展开
            <svg-icon icon-class="ios-arrow-down" />
          </el-button>
          <el-button v-else type="text">
            收起
            <svg-icon icon-class="ios-arrow-up" />
          </el-button>
        </a>
      </el-col>
    </el-row>
    <el-row v-if="collapse">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="订单号" prop="orderNo" label-for="orderNo">
          <el-input
            v-model="searchForm.orderNo"
            element-id="orderNo"
            placeholder="请输入订单号"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="订单状态" prop="orderStatus">
          <el-select
            v-model="searchForm.orderStatus"
            placeholder="请选择订单状态"
            clearable
            style="width: 100%;"
            @change="handleSubmit"
          >
            <el-option
              v-for="item in selects.orderStatusSelect"
              :value="item.value"
              :key="item.value"
              :label="item.displayValue"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="支付方式" prop="payType">
          <el-select
            v-model="searchForm.payType"
            placeholder="请选择支付方式"
            clearable
            style="width: 100%;"
            @change="handleSubmit"
          >
            <el-option
              v-for="item in selects.payTypeSelect"
              :value="item.value"
              :key="item.value"
              :label="item.displayValue"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="支付订单号" prop="transactionNo" label-for="transactionNo">
          <el-input
            v-model="searchForm.transactionNo"
            element-id="transactionNo"
            placeholder="请输入支付订单号"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="是否支付成功" prop="paySuccess">
          <el-select
            v-model="searchForm.paySuccess"
            placeholder="请选择是否支付成功"
            clearable
            style="width: 100%;"
            @change="handleSubmit"
          >
            <el-option
              v-for="item in selects.paySuccessSelect"
              :value="item.value"
              :key="item.value"
              :label="item.displayValue"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="是否申请售后" prop="applyedService">
          <el-select
            v-model="searchForm.applyedService"
            placeholder="请选择是否申请售后"
            clearable
            style="width: 100%;"
            @change="handleSubmit"
          >
            <el-option
              v-for="item in selects.applyedServiceSelect"
              :value="item.value"
              :key="item.value"
              :label="item.displayValue"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import * as utils from '@/utils/utils'
import * as ResponseStatus from '@/utils/response-status'
export default {
  name: 'GoodsOrderSearchQuick',
  data() {
    return {
      loading: {
        search: false,
      },
      conditionCount: 8,
      collapse: false,
      searchForm: {
        pageNo: 1,
        pageSize: 10,
        sortColumn: undefined,
        sortOrder: undefined,
        id: undefined,
        idMin: undefined,
        idMax: undefined,
        userId: undefined,
        userIdMin: undefined,
        userIdMax: undefined,
        userPhone: undefined,
        userNickname: undefined,
        userIsActive: undefined,
        userIsActiveMin: undefined,
        userIsActiveMax: undefined,
        shopId: undefined,
        shopIdMin: undefined,
        shopIdMax: undefined,
        shopTitle: undefined,
        shopIsActive: undefined,
        shopIsActiveMin: undefined,
        shopIsActiveMax: undefined,
        orderNo: undefined,
        totalAmount: undefined,
        totalAmountMin: undefined,
        totalAmountMax: undefined,
        payAmount: undefined,
        payAmountMin: undefined,
        payAmountMax: undefined,
        discountAmount: undefined,
        discountAmountMin: undefined,
        discountAmountMax: undefined,
        integralAmount: undefined,
        integralAmountMin: undefined,
        integralAmountMax: undefined,
        expressFee: undefined,
        expressFeeMin: undefined,
        expressFeeMax: undefined,
        orderStatus: undefined,
        orderStatusMin: undefined,
        orderStatusMax: undefined,
        payTime: undefined,
        payTimeMin: undefined,
        payTimeMax: undefined,
        payType: undefined,
        payTypeMin: undefined,
        payTypeMax: undefined,
        transactionNo: undefined,
        paySuccess: undefined,
        paySuccessMin: undefined,
        paySuccessMax: undefined,
        deliverTime: undefined,
        deliverTimeMin: undefined,
        deliverTimeMax: undefined,
        dealTime: undefined,
        dealTimeMin: undefined,
        dealTimeMax: undefined,
        remark: undefined,
        shopRemark: undefined,
        applyedService: undefined,
        applyedServiceMin: undefined,
        applyedServiceMax: undefined,
        version: undefined,
        versionMin: undefined,
        versionMax: undefined,
        createTime: undefined,
        createTimeMin: undefined,
        createTimeMax: undefined,
        updateTime: undefined,
        updateTimeMin: undefined,
        updateTimeMax: undefined,
        isActive: undefined,
        isActiveMin: undefined,
        isActiveMax: undefined,
      },
      dataDictCodes: ['YES_NO', 'ORDER_STATUS', 'PAY_TYPE'],
      selects: {
        userIsActiveSelect: [],
        shopIsActiveSelect: [],
        orderStatusSelect: [],
        payTypeSelect: [],
        paySuccessSelect: [],
        applyedServiceSelect: [],
        isActiveSelect: [],
      },
    }
  },
  computed: {},
  mounted() {
    this.initDataDict()
  },
  methods: {
    initDataDict() {
      utils
        .getDataDict(this.dataDictCodes)
        .then((response) => {
          if (response) {
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'userIsActive',
              dataProp: 'userIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'shopIsActive',
              dataProp: 'shopIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'ORDER_STATUS',
              formProp: 'orderStatus',
              dataProp: 'orderStatusSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'PAY_TYPE',
              formProp: 'payType',
              dataProp: 'payTypeSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'paySuccess',
              dataProp: 'paySuccessSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'applyedService',
              dataProp: 'applyedServiceSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'isActive',
              dataProp: 'isActiveSelect',
            })
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    resetForm(excludeProps) {
      for (let key in this.searchForm) {
        if (excludeProps && excludeProps.includes(key)) {
          continue
        }
        this.searchForm[key] = undefined
      }
    },
    handleSubmit() {
      this.$emit('quickSearch')
    },
    handleReset() {
      this.$emit('researchTable')
    },
  },
}
</script>
<style>
.ivu-quick-opt {
  text-align: right;
}
</style>